package com.jz.cash.client.service.impl;

import com.jz.cash.client.dao.RoleConfigDao;
import com.jz.cash.client.entity.RoleConfig;
import com.jz.cash.client.service.RoleConfigService;
import com.stip.mybatis.generator.plugin.BaseExample;
import com.stip.mybatis.generator.plugin.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class RoleConfigServiceImpl extends BaseService<RoleConfig, BaseExample, Long> implements RoleConfigService {

    @Autowired
    private RoleConfigDao roleConfigDao;

    @Override
    public Set<String> getRolesByUserId(Long id) {
        Set<String> roles = new HashSet<>();
        List<RoleConfig> all = roleConfigDao.findAllRolesByUserId(id);
        if (!CollectionUtils.isEmpty(all)) {
            roles = all.stream().map(f -> f.getDescription()).collect(Collectors.toSet());
        }
        return roles;
    }
}